package cn.dgut.training.controller;

import cn.dgut.training.dto.GroupBuyingRulesDTO;
import cn.dgut.training.entity.activity.GroupBuyingRules;
import cn.dgut.training.service.IGroupBuyingRulesService;
import cn.dgut.training.vo.BaseVO;
import cn.dgut.training.vo.CommonResponse;
import cn.dgut.training.vo.GroupBuyingRulesVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.swing.*;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/group-buying-rules")
public class GroupBuyingRulesController {

    @Resource
    private IGroupBuyingRulesService groupBuyingRulesService;

//    创建团购规则
    @PostMapping("/create")
    public CommonResponse createRules(@RequestBody @Valid GroupBuyingRulesDTO groupBuyingRulesDTO){
        GroupBuyingRulesVO groupBuyingRulesVO = groupBuyingRulesService.createRules(groupBuyingRulesDTO);
        BaseVO<GroupBuyingRulesVO> baseVO = new BaseVO<>();
        List<GroupBuyingRulesVO> GroupBuyingRulesVOList = new ArrayList<>();
        GroupBuyingRulesVOList.add(groupBuyingRulesVO);
        baseVO.setList(GroupBuyingRulesVOList);
        return CommonResponse.success(baseVO);
    }

//    修改团购规则
    @PostMapping("/update")
    public CommonResponse editRules(@RequestBody @Valid GroupBuyingRulesDTO groupBuyingRulesDTO){
        GroupBuyingRulesVO groupBuyingRulesVO = groupBuyingRulesService.editRules(groupBuyingRulesDTO);
        BaseVO<GroupBuyingRulesVO> baseVO = new BaseVO<>();
        List<GroupBuyingRulesVO> GroupBuyingRulesVOList = new ArrayList<>();
        GroupBuyingRulesVOList.add(groupBuyingRulesVO);
        baseVO.setList(GroupBuyingRulesVOList);
        return CommonResponse.success(baseVO);
    }

//    分页查询全部内容
    @PostMapping("/list")
    public CommonResponse listAllRulesByPage(@RequestBody @Valid GroupBuyingRulesDTO groupBuyingRulesDTO){
        return CommonResponse.success(groupBuyingRulesService.listGroupBuyingRulesByPage(groupBuyingRulesDTO));
    }

////    根据商品id查询团购规则
//    @PostMapping("/record")
//    public CommonResponse getGoodsRulesByGoodsId(@RequestBody @Valid GroupBuyingRulesDTO groupBuyingRulesDTO){
//        GroupBuyingRulesVO groupBuyingRulesVO = groupBuyingRulesService.getGoodsRulesByGoodsId(groupBuyingRulesDTO);
//        BaseVO<GroupBuyingRulesVO> baseVO = new BaseVO<>();
//        List<GroupBuyingRulesVO> GroupBuyingRulesVOList = new ArrayList<>();
//        GroupBuyingRulesVOList.add(groupBuyingRulesVO);
//        baseVO.setList(GroupBuyingRulesVOList);
//        return CommonResponse.success(baseVO);
//    }

//    手动下架团购规则
    @PostMapping("/delete")
    public CommonResponse deleteRules(@RequestBody @Valid GroupBuyingRulesDTO groupBuyingRulesDTO){
        GroupBuyingRulesVO groupBuyingRulesVO = groupBuyingRulesService.deleteRules(groupBuyingRulesDTO);
        BaseVO<GroupBuyingRulesVO> baseVO = new BaseVO<>();
        List<GroupBuyingRulesVO> GroupBuyingRulesVOList = new ArrayList<>();
        GroupBuyingRulesVOList.add(groupBuyingRulesVO);
        baseVO.setList(GroupBuyingRulesVOList);
        return CommonResponse.success(baseVO);
    }


//    @PostMapping("/delete")
//    public CommonResponse deleteById(@PathVariable("id") long id){
//        groupBuyingRulesService.removeById(id);
//        return CommonResponse.message();
//    }

}
